﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using ZFS.Library;
using ZFS.Library.Helper;
using ZFS.Model;
using ZFSData;
using ZFSData.InterFace.User;

namespace ZFS.ServerBusiness
{
    public class WCF_MenuManager : WCF_BaseManager<WCF_MenuManager>, IMenu
    {
        public tb_Menu AddEntity(tb_Menu entity)
        {
            var bytes = Server.AddEntityByMenu(ZipTools.CompressionObject(entity));
            ServiceResponse response = ZipTools.DecompressionObject(bytes) as ServiceResponse;
            if (response.Success)
                return response.Results;
            else
                throw new Exception(response.Message);
        }

        public bool DeleteEntity(tb_Menu entity)
        {
            var bytes = Server.DeleteEntityByMenu(ZipTools.CompressionObject(entity));
            ServiceResponse response = ZipTools.DecompressionObject(bytes) as ServiceResponse;
            if (response.Success)
                return response.Results;
            else
                throw new Exception(response.Message);
        }

        public bool ExistEntity(tb_Menu entity)
        {
            var bytes = Server.ExistEntityByMenu(ZipTools.CompressionObject(entity));
            ServiceResponse response = ZipTools.DecompressionObject(bytes) as ServiceResponse;
            if (response.Success)
                return response.Results;
            else
                throw new Exception(response.Message);
        }

        public List<View_MenuTree> GetMenuTrees()
        {
            var bytes = Server.GetMenuTrees();
            ServiceResponse response = ZipTools.DecompressionObject(bytes) as ServiceResponse;
            if (response.Success)
                return response.Results;
            else
                throw new Exception(response.Message);
        }

        public List<tb_Menu> GetModels(tb_Menu search)
        {
            var bytes = Server.GetModelsByMenu(ZipTools.CompressionObject(search));
            ServiceResponse response = ZipTools.DecompressionObject(bytes) as ServiceResponse;
            if (response.Success)
                return response.Results;
            else
                throw new Exception(response.Message);
        }

        public List<tb_Menu> GetPagingModels(int pageIndex, int pageSize, out int totalCount, tb_Menu search, bool Asc = false)
        {
            var bytes = Server.GetPagingModelsByMenu(pageIndex,pageSize,ZipTools.CompressionObject(search),Asc);
            ServiceResponse response = ZipTools.DecompressionObject(bytes) as ServiceResponse;
            if (response.Success)
            {
                totalCount = response.TotalCount;
                return response.Results;
            }
            else
                throw new Exception(response.Message);
        }

        public bool UpdateEntity(tb_Menu entity)
        {
            byte[] bytes = Server.UpdateEntityByMenu(ZipTools.CompressionObject(entity));
            ServiceResponse response = ZipTools.DecompressionObject(bytes) as ServiceResponse;
            if (response.Success)
                return response.Results;
            else
                throw new Exception(response.Message);
        }

        public bool UpdateMenus(List<tb_Menu> tb_Menus)
        {
            byte[] bytes = Server.UpdateMenus(ZipTools.CompressionObject(tb_Menus));
            ServiceResponse response = ZipTools.DecompressionObject(bytes) as ServiceResponse;
            if (response.Success)
                return response.Results;
            else
                throw new Exception(response.Message);
        }
    }
}
